package com.hjp.designmode.strategy.strategy.impl;

import com.hjp.designmode.strategy.domain.impl.Order;
import com.hjp.designmode.strategy.strategy.Strategy;
import com.hjp.designmode.strategy.utils.ArithmeticUtils;

/**
 * @Description:
 * @Author: huangjp6
 * @Date: 2022/3/7 14:22
 */
public class FullReductionStrategy implements Strategy {

    @Override
    public double countPrice(Order order) {
        double totalPrice1 = order.getTotalPrice();
        if (totalPrice1 >= 100) {
            totalPrice1 = ArithmeticUtils.sub(totalPrice1, 10);
        }

        double totalPrice2 = order.getTotalPrice();
        if (totalPrice2 >= 200) {
            totalPrice2 = ArithmeticUtils.sub(totalPrice2, 30);
        }

        if (ArithmeticUtils.compare(Double.toString(totalPrice1), Double.toString(totalPrice2)) == 1) {
            return totalPrice2;
        } else {
            return totalPrice1;
        }
    }
}
